import { ref } from 'vue';
import { UserInfo } from '@/types/user';

export const loginUser = ref<UserInfo>({
  username: '',
  password: '',
});

interface Rules {
  username: {
    type: string;
    message: string;
    required: boolean;
    trigger: string;
  }[];
  password: ({
    required: boolean;
    message: string;
    trigger: string;
    min?: undefined;
    max?: undefined;
  } | {
    min: number;
    max: number;
    message: string;
    trigger: string;
    required?: undefined;
  })[];
}

// 校验规则
export const rules = ref<Rules>({
  username: [
    {
      type: 'string',
      message: 'Name is incorrect...',
      required: true,
      trigger: 'blur',
    },
  ],
  password: [
    {
      required: true,
      message: 'Password could not be empty...',
      trigger: 'blur',
    },
    {
      min: 6,
      max: 30,
      message: "Password's length has to be 6 to 30 characters...",
      trigger: 'blur',
    },
  ],
});
